<template>
  <view class="control" @click="openPopup">
    <view class="text">{{ initYear || yearList[0] }}年</view>
    <view class="icon iconfont icon-xialajiantouxiao"></view>
  </view>
  <PopupWrap
    ref="oPopup"
    @confirm="handleConfirm"
    @cancel="handleCancel"
    :lists="yearList"
  ></PopupWrap>
</template>

<script lang="ts" setup>
import PopupWrap from "./PopupWrap.vue";

import { useYear, useYearList } from '@/store/index';

import { ref } from "vue";


defineProps({
  initYear: { type: String, default: '' }
})

const emit = defineEmits(['change']);

const [ yearList ] = useYearList();


const oPopup = ref(null) as any;

const openPopup = () => {
  oPopup.value.openPopup();
};

//  确认回调函数
const handleConfirm = (data: any) => {
  if(data) {
    emit('change', data);
  }
};

//  取消回调函数
const handleCancel = () => {};
</script>

<style lang="scss" scoped>
.control {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 140rpx;
  height: 48rpx;
  background: rgba(255, 255, 255, 0.49);
  border: 2rpx solid #ffffff;
  border-radius: 4rpx;

  .text {
    font-size: 24rpx;
    font-weight: bold;
  }

  .icon {
    margin-left: 10rpx;
    font-size: 24rpx;
    color: #999999;
  }
}
</style>
